<?php
class attrtagService extends commonService{
	public function __construct(){
		parent::__construct();
		$this->table_index=table('index_1');
	}
	
	public function t(){
		return array('attrtaglist','arc');
	}
	public function mod($id){
        $data=$this->model->_f($this->table_index,'*',$id);
		return $data;
    }
	
    public function mod_($post,$id){
        $result=array();
        
        $vali=validate::check('index_1',$post,'mod',array('id::!='=>$id));
        if($vali){
    		$result[0]=$this->model->_u($this->table_index,$post,$id);
    	}else{
    		$result[0]=false;
            $result[1]="\\n".implode("\\n",validate::getMsg());
    	}
        return $result;
    }
	
	public function del($id){
        $return=array();
		//查询tag名
		$query="select `tag` from `{$this->table_index}` where `id`=:id limit 1";
		$r=$this->m->get_field($query,array('id'=>$id));
		if(!$r) return false;
		
		//$r=addslashes($r);
		
		$return[0]=$this->model->_d($this->table_index,$id);//index表
		$query="delete from `{$this->t[0]}` where `tag`=:tag ";
		$this->m->query($query,array('tag'=>$r));
        return $return;
    }
	//统计tag数
	public function count_t($tag){
		//$tag=addslashes($tag);
		$query="select count(*) from `{$this->t[0]}` where `tag`=:tag";
		return $this->m->get_field($query,array('tag'=>$tag));
	}
	public function index_part($condition=array(),$extra='',$extra_data=array()){
        $return=array();
        $query="select * from `{$this->table_index}` where 1 {$extra} order by `id` desc";
        $p=new smart_pager(array($query,$extra_data),$this->m);
        //$p->address('&block_id=%block_id%','block_id',$condition['block_id']);
		foreach($condition as $k=>$v){
			$p->address("&{$k}=%{$k}%",$k,$v);
		}
        if($p->total_num>0){
            $return[]=$this->m->mselect($p->query,$extra_data);
            $return[]=$p;
        }
        return $return;
    }
	public function li($condition=array(),$extra='',$extra_data=array()){
        $return=array();
        $query="select `a`.`id`,`a`.`arc_id`,`a`.`tag`,`b`.`title` from `{$this->t[0]}` as `a` left join `{$this->t[1]}` as `b` on `a`.`arc_id`=`b`.`id` where 1 {$extra} order by `a`.`id` desc";
        $p=new smart_pager(array($query,$extra_data),$this->m);
        //$p->address('&block_id=%block_id%','block_id',$condition['block_id']);
		foreach($condition as $k=>$v){
			$p->address("&{$k}=%{$k}%",$k,$v);
		}
        if($p->total_num>0){
            $return[]=$this->m->mselect($p->query,$extra_data);
            $return[]=$p;
        }
        return $return;
    }
//
}